<?php

namespace Home\Controller;

use Home\Core\CommandSDK;

class IndexController extends BaseController
{
    /**
     * 获取下级结构信息列表
     */
    public function index()
    {
//        // 获取登录用户的管理员角色
//        $cookie = base64_decode($_COOKIE['user_info']);
//        parse_str($cookie,$userinfo);
//        $url = 'Index/realTimeVideo';
//        $this->redirect($url);
        $this->display();
    }
    /**
     * 修改密码
     */
    public function forget_password()
    {
        $param = I('post.');
        $param['oldpasswd']=substr(md5($param['oldpasswd']),0,16);
        $param['newpasswd']=substr(md5($param['newpasswd']),0,16);
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::ChangePassword, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }
    /**
     * 实时预览
     */
    public function livePreview(){

        $this->display();
    }
    /**
     * 录像回放
     */
    public function replay(){

        $this->display();
    }

    /**
     * 获取录像回放
     */
    public function getAccessVideo()
    {
        $cookie = base64_decode($_COOKIE['user_info']);
        parse_str($cookie,$userinfo);
        $param=I('post.');
        $param['pageid']=0;
        $param['pagecount']=0;
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::getAllVideo, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }

    /**
     * 获取前端回放
     */
    public function getFrontEndVideo()
    {
        $param = I('post.');
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::GetResourceList, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }

    /**
     * 获取资源组
     */
    public function accessResourceGroup()
    {
        $param = I('post.');
        $param['restype']=0;
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::GetResourceList, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }
    /**
     * 获取资源组下的资源列表
     */
    public function getResourceList()
    {
        $param = I('post.');
        $param['restype']=1;
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::GetResourceList, $param, 'GET');
        $array1 = json_decode(json_encode($return), true);
        $array1['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array1);
    }
    /**
     * 获取报警消息
     */
    public function getAlarmInformation()
    {
        $param = I('post.');
        $param['restype']=1;
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::GetAlarmInformation, $param, 'GET');
        $array1 = json_decode(json_encode($return), true);
        $array1['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array1);
    }
    /**
     * 资源管理
     */
    public function resourceManagement()
    {
        $this->display();
    }
    /**
     * 获取编码设备列表
     */
    public function GetCodingDeviceList()
    {
        $param = I('post.');
        if(empty($param['pageid'])){
            $param['pageid']=1;
        }else{
            $param['pageid']=$param['pageid'];
        }
        if(empty($param['pagecount'])){
            $param['pagecount']=10000000;
        }else{
            $param['pagecount']=$param['pagecount'];
        }
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::GetCodingDeviceList, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }
    /**
     * 添加编码设备
     */
    public function addCodingDevice()
    {
        $param = I('post.');
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::AddCodingDevice, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }

}